package com.abei.gas.service.Impl;

import com.abei.gas.entity.Card;
import com.abei.gas.entity.Device;
import com.abei.gas.entity.Employee;
import com.abei.gas.mapper.EmployeeMapper;
import com.abei.gas.service.EmployeeService;
import com.abei.gas.vo.DataVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Resource
    private EmployeeMapper employeeMapper;

    @Override
    public DataVo<Employee> findAll(Integer page, Integer limit) {
        List<Employee> c=employeeMapper.selectList(null);
        DataVo<Employee> datavo=new DataVo<>();
        datavo.setCode(0);
        datavo.setMsg("");
        IPage<Employee> cardpage=new Page<>(page,limit);
        IPage<Employee> result=employeeMapper.selectPage(cardpage,null);
        datavo.setCount(result.getTotal());
        c=result.getRecords();
        datavo.setData(c);
        return datavo;
    }

    @Override
    public DataVo<Employee> findById(String employeeid) {
        QueryWrapper<Employee> u = new QueryWrapper<>();
        u.like("id",employeeid);
        List<Employee> cardList=employeeMapper.selectList(u);
        DataVo<Employee> dataVO=new DataVo<>();
        dataVO.setCode(0);
        dataVO.setMsg("");
        Integer num = employeeMapper.selectCount(null);
        dataVO.setCount(Long.valueOf(num));
        dataVO.setData(cardList);
        return dataVO;
    }

    @Override
    public void deleteById(String employeeid) {
        Map<String,Object> columMap=new HashMap<>();
        columMap.put("id",employeeid);
        int i=employeeMapper.deleteByMap(columMap);
        System.out.println(i);
    }

    @Override
    public void Insert(Employee employee) {
        Employee u=new Employee();
        u.setId(employee.getId());
        u.setName(employee.getName());
        u.setStatus(employee.getStatus());
        u.setDepartment(employee.getDepartment());
        u.setDuty(employee.getDuty());
        u.setPay(employee.getPay());
        employeeMapper.insert(u);
    }

    @Override
    public void Update(String number, Employee employee) {
        QueryWrapper<Employee> u=new QueryWrapper<Employee>();
        u.eq("id",number);
        employeeMapper.update(employee,u);
    }
}
